home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 317 / asmsrc / as.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  8.4 KB  |  276 lines

  1. /* as.h - Copyright (C) 1987 Free Software Foundation, Inc. */
  2.   
  3. /*  This file is part of Gas, the GNU Assembler.
  4.  
  5. The GNU assembler is distributed in the hope that it will be
  6. useful, but WITHOUT ANY WARRANTY.  No author or distributor
  7. accepts responsibility to anyone for the consequences of using it
  8. or for whether it serves any particular purpose or works at all,
  9. unless he says so in writing.  Refer to the GNU Assembler General
  10. Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. the GNU Assembler, but only under the conditions described in the
  14. GNU Assembler General Public License.  A copy of this license is
  15. supposed to have been given to you along with the GNU Assembler
  16. so you can know your rights and responsibilities.  It should be
  17. in a file named COPYING.  Among other things, the copyright
  18. notice and this notice must be preserved on all copies.  */
  19.  
  20. #ifndef asH
  21. #define asH            /* Don't declare things twice. */
  22.  
  23. /*
  24.  * CAPITALISED names are #defined.
  25.  * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
  26.  * "lowercaseT" is a typedef of "lowercase" objects.
  27.  * "lowercaseP" is type "pointer to object of type 'lowercase'".
  28.  * "lowercaseS" is typedef struct ... lowercaseS.
  29.  *
  30.  * #define SUSPECT when debugging.
  31.  * #define DUMP to include data-structure dumpers.
  32.  * #define COMMON as "extern" for all modules except one, where you #define
  33.  *    COMMON as "".
  34.  * If TEST is #defined, then we are testing a module: #define COMMON as "".
  35.  */
  36.  
  37.  
  38.  
  39. /* These #defines are for parameters of entire assembler. */
  40.  
  41. /* #define SUSPECT JF remove for speed testing */
  42. /* #define DUMP */
  43. #define NDEBUG        /* JF disable asserts */
  44. /* These #includes are for type definitions etc. */
  45.  
  46. /* #include "style.h" */
  47. #include <stdio.h>
  48. #include <assert.h>
  49. #define obstack_chunk_alloc    xmalloc
  50. #define obstack_chunk_free    xfree
  51.  
  52. /* These defines are potentially useful */
  53. #define FALSE    (0)
  54. #define TRUE    (!FALSE)
  55. #define ASSERT    assert
  56. #define BAD_CASE(value)                            \
  57. {                                    \
  58.   as_fatal ("Case value %d unexpected at line %d of file \"%s\"\n",    \
  59.        value, __LINE__, __FILE__);                    \
  60. }
  61.  
  62.  
  63.  
  64.  
  65. /* These are assembler-wide concepts */
  66.  
  67.  
  68. #ifndef COMMON
  69. #ifdef TEST
  70. #define COMMON            /* declare our COMMONs storage here. */
  71. #else
  72. #define COMMON extern        /* our commons live elswhere */
  73. #endif
  74. #endif
  75.                 /* COMMON now defined */
  76.  
  77. #ifdef SUSPECT
  78. #define register        /* no registers: helps debugging */
  79. #define know(p) ASSERT(p)    /* know() is less ugly than #ifdef SUSPECT/ */
  80.                 /* assert()/#endif. */
  81. #else
  82. #define know(p)            /* know() checks are no-op.ed */
  83. #endif                /* #ifdef SUSPECT */
  84.  
  85.  
  86. char    *xmalloc();        /* keep C compilers happy */
  87. char    *xrealloc();        /* " */
  88. void    free();            /* " */
  89. #define xfree free
  90.  
  91. /* input_scrub.c */
  92.  
  93. /*
  94.  * Supplies sanitised buffers to read.c.
  95.  * Also understands printing line-number part of error messages.
  96.  */
  97.  
  98.                 /* Line number things. */
  99. int    seen_at_least_1_file();
  100. void    bump_line_counters();
  101. void    new_logical_line();
  102. void    as_where();
  103. void    as_perror();
  104. void    as_howmuch();
  105.                 /* Sanitising things. */
  106. void    input_scrub_begin();
  107. void    input_scrub_end();
  108. char    *input_scrub_new_file();
  109. char    *input_scrub_next_buffer();
  110.  
  111. /* subsegs.c     Sub-segments. Also, segment(=expression type)s.*/
  112.  
  113. /*
  114.  * This table describes the use of segments as EXPRESSION types.
  115.  *
  116.  *    X_seg    X_add_symbol  X_subtract_symbol    X_add_number
  117.  * SEG_NONE                        no (legal) expression
  118.  * SEG_PASS1                        no (defined) "
  119.  * SEG_BIG                    *    > 32 bits const.
  120.  * SEG_ABSOLUTE                         0
  121.  * SEG_DATA        *                 0
  122.  * SEG_TEXT        *            0
  123.  * SEG_BSS        *            0
  124.  * SEG_UNKNOWN        *            0
  125.  * SEG_DIFFERENCE    0        *    0
  126.  *
  127.  * The blank fields MUST be 0, and are nugatory.
  128.  * The '0' fields MAY be 0. The '*' fields MAY NOT be 0.
  129.  *
  130.  * SEG_BIG: X_add_number is < 0 if the result is in
  131.  *    generic_floating_point_number.  The value is -'c' where c is the
  132.  *    character that introduced the constant.  e.g. "0f6.9" will have  -'f'
  133.  *    as a X_add_number value.
  134.  *    X_add_number > 0 is a count of how many littlenums it took to
  135.  *    represent a bignum.
  136.  * SEG_DIFFERENCE:
  137.  * If segments of both symbols are known, they are the same segment.
  138.  * X_add_symbol != X_sub_symbol (then we just cancel them, => SEG_ABSOLUTE).
  139.  */
  140.  
  141. typedef enum
  142. {
  143.     SEG_ABSOLUTE,
  144.     SEG_TEXT,
  145.     SEG_DATA,
  146.     SEG_BSS,
  147.     SEG_UNKNOWN,
  148.     SEG_NONE,        /* Mythical Segment: NO expression seen. */
  149.     SEG_PASS1,        /* Mythical Segment: Need another pass. */
  150.     SEG_GOOF,        /* Only happens if AS has a logic error. */
  151.                 /* Invented so we don't crash printing */
  152.                 /* error message involving weird segment. */
  153.     SEG_BIG,            /* Bigger than 32 bits constant. */
  154.     SEG_DIFFERENCE        /* Mythical Segment: absolute difference. */
  155. }        segT;
  156. #define SEG_MAXIMUM_ORDINAL (SEG_DIFFERENCE)
  157.  
  158. typedef unsigned char    subsegT;
  159.  
  160. COMMON subsegT            now_subseg;
  161.                 /* What subseg we are accreting now? */
  162.  
  163.  
  164. COMMON segT            now_seg;
  165.                 /* Segment our instructions emit to. */
  166.                 /* Only OK values are SEG_TEXT or SEG_DATA. */
  167.  
  168.  
  169. extern char    *seg_name[];
  170. extern int    seg_N_TYPE[];
  171. extern segT    N_TYPE_seg[];
  172. void    subsegs_begin();
  173. void    subseg_change();
  174. void    subseg_new();
  175.  
  176. /* relax() */
  177.  
  178. typedef enum
  179. {
  180.     rs_fill,        /* Variable chars to be repeated fr_offset */
  181.                 /* times. Fr_symbol unused. */
  182.                 /* Used with fr_offset == 0 for a constant */
  183.                 /* length frag. */
  184.  
  185.     rs_align,        /* Align: Fr_offset: power of 2. */
  186.                 /* 1 variable char: fill character. */
  187.     rs_org,            /* Org: Fr_offset, fr_symbol: address. */
  188.                 /* 1 variable char: fill character. */
  189.  
  190.     rs_machine_dependent
  191. }
  192. relax_stateT;
  193.  
  194. /* typedef unsigned char relax_substateT; */
  195. /* JF this is more likely to leave the end of a struct frag on an align
  196.    boundry.  Be very careful with this.  */
  197. typedef unsigned long int relax_substateT;
  198.  
  199. typedef unsigned long int relax_addressT;/* Enough bits for address. */
  200.                 /* Still an integer type. */
  201.  
  202.  
  203. /* frags.c */
  204.  
  205. /*
  206.  * A code fragment (frag) is some known number of chars, followed by some
  207.  * unknown number of chars. Typically the unknown number of chars is an
  208.  * instruction address whose size is yet unknown. We always know the greatest
  209.  * possible size the unknown number of chars may become, and reserve that
  210.  * much room at the end of the frag.
  211.  * Once created, frags do not change address during assembly.
  212.  * We chain the frags in (a) forward-linked list(s). The object-file address
  213.  * of the 1st char of a frag is generally not known until after relax().
  214.  * Many things at assembly time describe an address by {object-file-address
  215.  * of a particular frag}+offset.
  216.  
  217.  BUG: it may be smarter to have a single pointer off to various different
  218. notes for different frag kinds. See how code pans out.
  219.  
  220.  
  221.  */
  222. struct frag            /* a code fragment */
  223. {
  224.     long unsigned int fr_address; /* Object file address. */
  225.     struct frag *fr_next;    /* Chain forward; ascending address order. */
  226.                 /* Rooted in frch_root. */
  227.  
  228.     long int fr_fix;    /* (Fixed) number of chars we know we have. */
  229.                 /* May be 0. */
  230.     long int fr_var;    /* (Variable) number of chars after above. */
  231.                 /* May be 0. */
  232.     struct symbol *fr_symbol; /* For variable-length tail. */
  233.     long int fr_offset;    /* For variable-length tail. */
  234.     char    *fr_opcode;    /*->opcode low addr byte,for relax()ation*/
  235.     relax_stateT fr_type;   /* What state is my tail in? */
  236.     relax_substateT    fr_subtype;
  237.     char    fr_literal [1];    /* Chars begin here. */
  238.                 /* One day we will compile fr_literal[0]. */
  239. };
  240. #define SIZEOF_STRUCT_FRAG\
  241.  ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
  242.                 /* We want to say fr_literal[0] above. */
  243.  
  244. typedef struct frag fragS;
  245.  
  246. COMMON fragS *    frag_now;    /* -> current frag we are building. */
  247.                 /* This frag is incomplete. */
  248.                 /* It is, however, included in frchain_now. */
  249.                 /* Frag_now->fr_fix is bogus. Use: */
  250. /* Virtual frag_now->fr_fix==obstack_next_free(&frags)-frag_now->fr_literal.*/
  251.  
  252. COMMON fragS zero_address_frag;    /* For foreign-segment symbol fixups. */
  253. COMMON fragS  bss_address_frag;    /* For local common (N_BSS segment) fixups. */
  254.  
  255. void        frag_new();
  256. char *        frag_more();
  257. char *        frag_var();
  258. void        frag_wane();
  259. void        frag_align();
  260.  
  261.  
  262. /* main program "as.c" (command arguments etc) */
  263.  
  264. COMMON char
  265. flagseen[128];            /* ['x'] TRUE if "-x" seen. */
  266.  
  267. COMMON char *
  268. out_file_name;            /* name of emitted object file */
  269.  
  270. COMMON int    need_pass_2;    /* TRUE if we need a second pass. */
  271.  
  272.  
  273. #endif                /* #ifdef asH */
  274.  
  275. /* end: as.h */
  276.